package com.example.learning3;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;

public class MySQliteOpenHelper extends SQLiteOpenHelper {

    private static SQLiteOpenHelper mInstance;
    public static synchronized SQLiteOpenHelper getInstance(Context context){
        if(mInstance==null){
            mInstance=new MySQliteOpenHelper(context,"lxh.db",null,1);
        }
        return mInstance;
    }
    //构造函数私有化

    private MySQliteOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    //初始化,数据初始化，数据库第一次创建时用。此函数只执行一次。
    //主键必须唯一primary key
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql="create table learning_data(_id integer primary key autoincrement,data_year text,data_month text,data_day text,learning_time_hour integer,learning_time_minute integer,learning_time_second integer)";
        db.execSQL(sql);
        String sql1 = "insert into learning_data(data_year,data_month,data_day,learning_time_hour,learning_time_minute,learning_time_second) values('year','month','day','learning_hour','learning_minute','learning_second')";
        db.execSQL(sql1);
        String sql2 = "insert into learning_data(data_year,data_month,data_day,learning_time_hour,learning_time_minute,learning_time_second) values('year','month','day','learning_hour','learning_minute','learning_second')";
        db.execSQL(sql2);
        String sql3 = "insert into learning_data(data_year,data_month,data_day,learning_time_hour,learning_time_minute,learning_time_second) values('year','month','day','learning_hour','learning_minute','learning_second')";
        db.execSQL(sql3);
        String sql4 = "insert into learning_data(data_year,data_month,data_day,learning_time_hour,learning_time_minute,learning_time_second) values('year','month','day','learning_hour','learning_minute','learning_second')";
        db.execSQL(sql4);
        String sql5 = "insert into learning_data(data_year,data_month,data_day,learning_time_hour,learning_time_minute,learning_time_second) values('year','month','day','learning_hour','learning_minute','learning_second')";
        db.execSQL(sql5);
        String sql6 = "insert into learning_data(data_year,data_month,data_day,learning_time_hour,learning_time_minute,learning_time_second) values('year','month','day','learning_hour','learning_minute','learning_second')";
        db.execSQL(sql6);
        String sql7 = "insert into learning_data(data_year,data_month,data_day,learning_time_hour,learning_time_minute,learning_time_second) values('year','month','day','learning_hour','learning_minute','learning_second')";
        db.execSQL(sql7);

    }
    //更新
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}